<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<!--<el-form-item>-->
					<!--<el-input v-model="filters.username" placeholder="渠道商名称"></el-input>-->
				<!--</el-form-item>-->
				<!--<el-form-item>-->
					<!--<el-input v-model="filters.rechargeamount" placeholder="充值金额"></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="渠道商" prop="useruuid" >
					<el-select v-model="filters.useruuid" placeholder="请选择渠道商"  filterable >
						<el-option value="0" label="全部" >全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd"   v-model="filters.rechargetime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findRechargeRecord">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="exportUpRechargeRecord">导出</el-button>
				</el-form-item>

			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="records" highlight-current-row v-loading="listLoading" border max-height="620"  style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="user.username" label="充值渠道商名称" width="180"  show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="rechargeamount" label="充值金额" width="120"  show-overflow-tooltip   >
			</el-table-column>
            <el-table-column prop="balance" label="充值后余额" width="120"  show-overflow-tooltip   >
            </el-table-column>
            <el-table-column prop="rechargetime" label="充值时间" width="180"  show-overflow-tooltip   >
			</el-table-column>
			<el-table-column prop="payType" label="充值类型" width="120" :formatter="formatPayType" >
			</el-table-column>
			<el-table-column prop="rechargestatus" label="充值状态" width="120" :formatter="formatStatus" >
			</el-table-column>
			<el-table-column prop="remark" label="备注" min-width="180"  >
			</el-table-column>
		</el-table>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>
	</section>
</template>

<script>
	import util from '../../common/js/util'
	import {findRechargeRecord,findAllUpShopInfo,exportUpRechargeRecord} from '../../api/api';

	export default {
		data() {
			return {
				filters: {
                    username: '',
                    rechargeamount:'',
                    rechargetime:'',
					endtime:'',
                    useruuid:''
				},
                total: 0,
                start:0,
                pageSize:10,
				records: [],
				listLoading: false,
                users:[]
			}
		},
		methods: {
			//状态转换
			formatStatus: function (row, column) {
				return row.rechargestatus ==  1 ? '充值成功' : row.sex == 0 ? '充值失败' : '未知';
			} ,
            formatPayType: function (row, column) {
                return row.payType ==  1 ? '充值' : row.payType == 2 ? '扣款' : '未知';
            } ,
			//获取用户列表
            findRechargeRecord() {
			    let para = {
					start: this.start,
					pageSize:this.pageSize,
                    starttime :  this.filters.rechargetime = (! this.filters.rechargetime || this.filters.rechargetime == '') ? '' : util.formatDate.format(new Date( this.filters.rechargetime), 'yyyy-MM-dd'),
                    endtime: this.filters.endtime = (! this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date( this.filters.endtime), 'yyyy-MM-dd'),
                    rechargeamount: this.filters.rechargeamount,
                    username: this.filters.username,
                    useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid
           	 	};
				this.listLoading = true;
                findRechargeRecord(para).then((datas) => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.records = data.result;
                        this.total = data.totalCount;
                    }
					this.listLoading = false;
				}).catch(function(error){
				    console.log(error);
				});

			},exportUpRechargeRecord(){
				let para = {
					start: this.start,
					pageSize:this.pageSize,
					starttime :  this.filters.rechargetime = (! this.filters.rechargetime || this.filters.rechargetime == '') ? '' : util.formatDate.format(new Date( this.filters.rechargetime), 'yyyy-MM-dd'),
					endtime: this.filters.endtime = (! this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date( this.filters.endtime), 'yyyy-MM-dd'),
					rechargeamount: this.filters.rechargeamount,
					username: this.filters.username,
					useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid
				};
				this.listLoading = true;
				exportUpRechargeRecord(para).then((datas) => {
					let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						window.open(data.path);
					}
				}).catch(function(error){
					console.log(error);
				});
			},findAllUserShopInfo:function(){
			    let para = {useruuid:''};
                findAllUpShopInfo(para).then(datas => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.users =   data;
                    }
                });
			}
            ,handleCurrentChange:function(val){
                this.start = val - 1;
                this.findRechargeRecord();
            },
            handleSizeChange:function(val){
                this.pageSize = val;
                this.findRechargeRecord();
            }
		},
		mounted() {
		    this.findAllUserShopInfo();
			this.findRechargeRecord();
		}
	}

</script>

<style scoped>

</style>
